package com.wenhuitec.sysui.view;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.wenhuitec.sysui.R;

/**
 * 菜品展示时的库存和下架按钮视图
 */
public class MenuFoodButton extends RelativeLayout {

    private RelativeLayout mButRv;
    private TextView mContentTv;
    private RelativeLayout mTipsRv;
    private TextView mTipsTv;
    private OnClick mOnClick;


    public MenuFoodButton(Context context, AttributeSet attrs) {
        super(context, attrs);
        LayoutInflater.from(context).inflate(R.layout.view_menufood_button, this, true);
        mButRv = (RelativeLayout) findViewById(R.id.butRv);
        mContentTv = (TextView) findViewById(R.id.contentTv);
        mTipsRv = (RelativeLayout) findViewById(R.id.tipsRv);
        mTipsTv = (TextView) findViewById(R.id.tipsTv);
        mButRv.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mOnClick != null) {
                    mOnClick.onClick();
                }
            }
        });
    }


    public void setPutShelves(boolean putShelves, int position, OnClick onClick) {
        mOnClick = onClick;
        mTipsTv.setText("已下架");
        updatePutStatus(putShelves);
    }

    public void updatePutStatus(boolean putShelves) {
        if (putShelves) {
            mContentTv.setText("下架");
            mTipsRv.setVisibility(GONE);
        } else {
            mContentTv.setText("上架");
            mTipsRv.setVisibility(VISIBLE);
        }
    }

    public void setKuNum(int num, OnClick onClick) {

        mOnClick = onClick;
        mTipsTv.setText("已售罄");
        mContentTv.setText("库存" + num);
        if (num <= 0) {
            mTipsRv.setVisibility(VISIBLE);
        } else {
            mTipsRv.setVisibility(GONE);
        }
    }

    public interface OnClick {
        void onClick();
    }
}
